import 'dart:math';

import 'package:dodoclub/pages/comm/comm_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class ViewPage extends StatefulWidget {
  const ViewPage({
    Key? key,
    required this.index,
  }) : super(key: key);

  final int? index;

  @override
  _ViewPageState createState() => _ViewPageState();
}

class _ViewPageState extends State<ViewPage> {
  final CommController controller = Get.put(CommController());

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);

    // 创建 Random 对象
    Random random = Random();

    // 生成 1 到 9 之间的随机整数
    int randomNumber = random.nextInt(17);
    // int randomNumber2 = random.nextInt(17);

    // int randomNumber3 = random.nextInt(9);

    var item = controller.items[widget.index!];

    return Scaffold(
      backgroundColor: Color(0xFFf1f2f3),
      appBar: AppBar(
        scrolledUnderElevation: 0.0,
        title: Text(
          ' ',
        ),
      ),
      body: Container(
        color: theme.colorScheme.primaryContainer,
        padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 12),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start, // 确保图片在顶部对齐
          children: [
            // Container(
            //   width: 60,
            //   height: 60,
            //   margin: const EdgeInsets.fromLTRB(0, 0, 12, 0),
            //   decoration: BoxDecoration(
            //     borderRadius: BorderRadius.circular(30),
            //     // image: const DecorationImage(
            //     //   image: NetworkImage(
            //     //       "https://profile-avatar.csdnimg.cn/5b9b486a599e45a7bd8b545652de34c5_xiongxu74110.jpg"),
            //     //   fit: BoxFit.cover,
            //     // ),
            //     image: DecorationImage(
            //       image: AssetImage(
            //           "assets/images/${randomNumber2}.jpg"), // 使用本地图片
            //       fit: BoxFit.cover,
            //     ),
            //   ),
            // ),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    item["title"] ?? 'No Title',
                    style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                  ),
                  Row(
                    children: [
                      Text(
                        item["date"] ?? 'No date',
                        style: TextStyle(color: Colors.grey.shade500),
                      )
                    ],
                  ),
                  Text(
                    item["value"] ?? 'No Value',
                    maxLines: 10,
                    overflow: TextOverflow.ellipsis,
                  ),
                  Container(
                    width: double.infinity,
                    height: 180,
                    margin: const EdgeInsets.fromLTRB(0, 6, 12, 0),
                    decoration: BoxDecoration(
                      color: Color.fromARGB(255, 197, 245, 168),
                      borderRadius: BorderRadius.circular(8.0),
                      // image: DecorationImage(
                      //   image: NetworkImage(
                      //     "https://profile-avatar.csdnimg.cn/5b9b486a599e45a7bd8b545652de34c5_xiongxu74110.jpg", // 替换为你的图片URL
                      //   ),
                      //   fit: BoxFit.cover,
                      // ),
                      image: DecorationImage(
                        image: AssetImage(
                            "assets/images/${randomNumber}.jpg"), // 使用本地图片
                        fit: BoxFit.cover,
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
